package clientUtilGUI;

import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringReader;
import java.util.Vector;

import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JTable;
import javax.swing.ListCellRenderer;
import javax.swing.UIManager;
import javax.swing.table.TableCellRenderer;

/**
 * 
 * @author Java2s.com
 *
 */


public class MultiLineHeaderRenderer extends JList implements TableCellRenderer{
	private Color colorTxt; 
	
	public MultiLineHeaderRenderer(Color background, Color foreground, Font font) {
	    setOpaque(true);
	    colorTxt = foreground;
//	    setForeground(foreground);
	    setBackground(background);
	    setBorder(UIManager.getBorder("TableHeader.cellBorder"));
	    setFont(font);
	    ListCellRenderer renderer = getCellRenderer();
	    ((JLabel) renderer).setHorizontalAlignment(JLabel.CENTER);
	    setCellRenderer(renderer);
	  }

	  public Component getTableCellRendererComponent(JTable table, Object value,
	      boolean isSelected, boolean hasFocus, int row, int column) {
	    String str = (value == null) ? "" : value.toString();
	    BufferedReader br = new BufferedReader(new StringReader(str));
	    String line;
	    Vector v = new Vector();
	    try {
	      while ((line = br.readLine()) != null) {
	        v.addElement(line);
	      }
	    } catch (IOException ex) {
	      ex.printStackTrace();
	    }
	    setListData(v);
	    setForeground(colorTxt);
	    return this;
	  }
}

